<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container">
      <el-form :inline="true">
        <el-form-item >
          <el-input @keyup.enter.native="handleFilter" clearable v-model="listQuery.usersPhone" style="width: 200px;" class="filter-item" placeholder="请输入手机号" ></el-input>
        </el-form-item>
        <el-form-item >
          <el-input @keyup.enter.native="handleFilter" clearable v-model="listQuery.nickName" style="width: 200px;" class="filter-item" placeholder="请输入用户昵称" ></el-input>
        </el-form-item>
        <el-form-item >
          <el-date-picker
            v-model="listQuery.date"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item  >
          <el-select v-model="listQuery.financeType" placeholder="请选择类型" clearable>
           <el-option label="押金缴纳" value="3"></el-option>
            <el-option label="押金退还" value="4"></el-option>
        </el-select>
        </el-form-item>
      </el-form>
      <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">{{$t('common.Search')}}</el-button>
    </div>
    <!-- table 表格 -->
    <el-table  :data="list" v-loading="loading.list" element-loading-text="给我一点时间" border fit highlight-current-row
      style="width: 100%">
      <el-table-column  label="序号" prop='index' />
      <el-table-column  label="用户昵称" prop='nickName' />
      <el-table-column  label="手机号" prop='usersPhone'/>
      <el-table-column  label="缴纳类型" prop='financeType'>
        <template slot-scope="scope">
          {{scope.row.financeType == 3?'押金缴纳':'押金退还'}}
        </template>
      </el-table-column>
      <el-table-column  label="押金金额" >
        <template slot-scope="scope">
         <span v-if="scope.row.financeType == 3">{{scope.row.expensesAmount}}</span>
         <span v-if="scope.row.financeType == 4">{{scope.row.revenueAmount}}</span> 
        </template>
      </el-table-column>
      <el-table-column  label="时间" prop='ctime'>
        <template slot-scope="scope">
          {{scope.row.ctime | parseTime}}
        </template>
      </el-table-column>

    </el-table>
    <!-- pagination 分页 -->
    <div class="pagination-container">
      <el-pagination 
      background 
      @size-change="handleSizeChange" 
      @current-change="handleCurrentChange" 
      :current-page="listQuery.pageNo" 
      :page-sizes="[10, 20, 30, 40]" 
      :page-size="listQuery.pageSize" 
      layout="total, sizes, prev, pager, next, jumper" 
      :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import CountTo from 'vue-count-to'
import { userBackList, selectDeposite, putDeposit } from '@/api/financial'
export default {
  name: 'financial_back',
  components: {
    CountTo,
  },
  data() {
    return {
      total: 0,
      parameter: '',
      listQuery: {
        pageNo: 1,
        pageSize: 10,
        usersPhone: '',
        date: '',
        financeType: '',
        nickName:''
      },
      value: '',
      list: null,
      loading: {
        list: false,
        download: false
      }
    }
  },
 
  created() {
    this.getList()
    // this.selectDeposites()
  },
  methods: {
    changes(val) {
      console.log(val);
    },
    async getList() {
      this.loading.list = true
      try {
        const { data } = await userBackList(this.filters)
        this.list = data.records.map((item, index) => ({index: index + 1, ...item}))
        this.total = data.total
      } catch (error) {
        
      }
      this.loading.list = false
     
    },
    //查询押金
    async selectDeposites() {
      try{
        const { data } = await selectDeposite()
        this.parameter = data.parameter
      } catch(error) {

      }
    },
    //修改押金
    async updateSystem() {
      try{
        const { data } = await putDeposit({
          price: this.parameter
        })
        this.$message({
          type:'success',
          message: '修改成功'
        })
        this.selectDeposites()
      }catch(error) {

      }
      
    },
    handleFilter() {
      this.listQuery.pageNo = 1
      this.getList()
    },
    handleSizeChange(val) {
      this.listQuery.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.pageNo = val
      this.getList()
    },
    formatDate(date, offset){
      if(date && typeof date  == 'object' ){
          const d = date[offset];
          return new Date(d).getTime()
      }
      return ''
    },
  },
  computed: {
    filters() {
      return {
        usersPhone: this.listQuery.usersPhone,
        financeType: this.listQuery.financeType,
        nickName: this.listQuery.nickName,
        startTime: this.formatDate(this.listQuery.date,0),
        endTime: this.formatDate(this.listQuery.date,1),
        pageNo: this.listQuery.pageNo,
        pageSize: this.listQuery.pageSize,
      }
    },
  }
}
</script>
